﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Sisocana.Core;
using Sisocana.Core.Models;

namespace Sisocana.Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MobileServices" in code, svc and config file together.
    public class MobileServices : IMobileServices
    {
        public List<LightCatastrophe> GetCatastrophes()
        {
            return siteSrv.GetAll().Select(sitio => new LightCatastrophe(sitio.id, sitio.nombreCatastrofe)).ToList<LightCatastrophe>();
        }

        public bool SendHelpRequest(HelpRequest message)
        {
            try
            {
                PersonaAyudaModel persona = new PersonaAyudaModel()
                                            {
                                                idSitio = message.catastropheId,
                                                nombre = message.firstName,
                                                apellido = message.lastName,
                                                descripcionSituacion = message.situationDescription,
                                                foto = message.image ?? new DataImagen(),
                                                coordX = message.longitude,
                                                coordY = message.latitude
                                            };
                personaSrv.makeHelpRequest(persona);
                return true;
            }
            catch (Exception) { return false; }            
        }        

        public MobileServices(SiteService siteService, PersonaService personService)
        {
            siteSrv = siteService;
            personaSrv = personService;
        }

        public MobileServices() : this(new SiteService(), new PersonaService()) { }

        PersonaService personaSrv;
        SiteService siteSrv;
    }
}
